package com.uade.magicCompany.controler;

import java.util.ArrayList;
import java.util.Map;
import java.util.List;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.uade.magicCompany.controler.utitilities.ActionConstants;
import com.uade.magicCompany.services.GestionRapidPassImpl;
import com.uade.magicCompany.services.GestionRapidpass;
import com.uade.magicCompany.model.Atraccion;
import com.uade.magicCompany.model.RapidPass;

public class RapidPassAction extends ActionSupport implements SessionAware {
	
	private static final long serialVersionUID = 1L;
	private Map<String, Object> userSession ;
	private List<RapidPass> rapids;
	private List<Atraccion> atracciones;
	private List<RapidPass> passesResponse;

	@Override
	public void setSession(Map<String, Object> session) {
		userSession = session;
	}
	
	public List<RapidPass> getPassesResponse() {
		return passesResponse;
	}

	public void setPassesResponse(List<RapidPass> passesResponse) {
		this.passesResponse = passesResponse;
	}

	public String execute() throws Exception {
		GestionRapidpass servicioRapidPass=new GestionRapidPassImpl();
		if(null==ActionContext.getContext().getSession().get(ActionConstants.USER_LOGGED)){
			return "login";
		}
		String user=(String)ActionContext.getContext().getSession().get(ActionConstants.USER_LOGGED);
		//Si hay rapid pass para la entrada buscar entidad de rapidpass.
		List<RapidPass> rapidPasses=servicioRapidPass.buscarRapidPassDeEntrada(Long.valueOf(user));
		if (rapidPasses!=null && !rapidPasses.isEmpty()){
			setRapids(rapidPasses);
			setPassesResponse(rapidPasses);
			return "rapidPasses";
		}	else	{
			atracciones=new ArrayList<Atraccion>();
			//Id de un parque. Un solo parque entrada que aprque. 
			setAtracciones(servicioRapidPass.buscarAtracciones(1));
			return "atracciones";
			
		}
		
	}

	public List<RapidPass> getRapids() {
		return rapids;
	}

	public void setRapids(List<RapidPass> rapids) {
		this.rapids = rapids;
	}

	public List<Atraccion> getAtracciones() {
		return atracciones;
	}

	public void setAtracciones(List<Atraccion> atracciones) {
		this.atracciones = atracciones;
	}

	
}
